package com.ruoyi.law.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageCondition;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.law.domain.entity.LawPresets;
import com.ruoyi.law.service.ILawPresetsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 文书生成预设 前端控制器
 * </p>
 *
 * @author code
 * @since 2023-05-04
 */
@Api(tags = "文书生成预设信息设置")
@RestController
@RequestMapping("/presets")
public class LawPresetsController extends BaseController {

    @Autowired
    private ILawPresetsService presetsService;

    @Anonymous
    @ApiOperation("列表")
    @GetMapping("/list")
    public R<Page<LawPresets>> list(PageCondition<LawPresets> pageCondition, String bigType, String smallType) {
        LambdaQueryWrapper<LawPresets> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(bigType), LawPresets::getBigType, bigType)
                .eq(StrUtil.isNotBlank(smallType), LawPresets::getSmallType, smallType);
        Page<LawPresets> page = presetsService.page(pageCondition.toPage(), wrapper);
        return R.ok(page);
    }

    @Anonymous
    @ApiOperation("详情")
    @GetMapping("/info")
    public R<LawPresets> info(Long id) {
        LawPresets byId = presetsService.getById(id);
        return R.ok(byId);
    }

    @ApiOperation("新增")
    @PostMapping("/save")
    public R<String> save(@RequestBody LawPresets presets) {
        presetsService.save(presets);
        return R.ok();
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public R<String> update(@RequestBody LawPresets presets) {
        presetsService.updateById(presets);
        return R.ok();
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public R<String> delete(@RequestBody Long id) {
        presetsService.removeById(id);
        return R.ok();
    }

}
